﻿@model IEnumerable<BootyBay.Models.ApplicationProcessorArchitecture>

@{
    ViewBag.Title = "AppSubmission";
    Layout = "~/Views/Shared/_Layout.cshtml";
}

<h2>AppSubmission</h2>
@if (ViewBag.Status == (int)BootyBay.Models.AppStatus.Published)
{ 
    <p>This version has been published to app store.</p>
}
else
{
    <p>
        appx: <input type="file" id="appx" /> <br />
        cer: <input type="file" id="cer" /> <br />
        <input type="button" onclick="upload();" value="Upload" />
        <progress id="progressBar" value="0" max="100"> </progress>
        <div id="submission"></div>
        <script type="text/javascript">
        function upload() {
            var appx = document.getElementById("appx").files[0];
            var cer = document.getElementById("cer").files[0];

            var url = "@Url.Content("~/package/upload/")@ViewBag.id";

            var form = new FormData();
            form.append("file", appx);
            form.append("file", cer);

            if (window.XMLHttpRequest) {
                var oReq = new XMLHttpRequest();

                oReq.open("POST", url, true);
                oReq.onload = function () {
                    //var jsonResponse = JSON.parse(oReq.responseText)
                    //alert(jsonResponse.IdentityName);
                    $("#submission").replaceWith(oReq.responseText);
                };
                oReq.upload.onprogress = progressFunction;
                oReq.send(form);

            } else {
                // XMLHttpRequest not supported; handle fallback
            }
        }

        function progressFunction(e) {
            var progressBar = document.getElementById("progressBar");
            if (e.lengthComputable) {
                progressBar.max = e.total;
                progressBar.value = e.loaded;
            }
        }
        </script>
    </p>
    <div>
        @foreach (var package in Model)
        {
            <p>@package.PackageLocationUrl</p>
        }
    </div>
}